package com.app.common.dataDictionary.PO;

import java.util.BitSet;
import java.util.HashMap;
import java.util.Map;

import com.app.common.dataDictionary.DE.DE_APPVERSION_ID;
import com.app.common.dataDictionary.DE.DE_APPVERSION_NUMBER;
import com.app.common.dataDictionary.DE.DE_APPVERSION_OPPTIME;
import com.app.common.dataDictionary.DE.DE_APPVERSION_UPDATEINFO;
import com.app.common.dataDictionary.DE.DE_APPVERSION_UPDATEURL;
import com.app.common.dataDictionary.DE.DE_PHONETYPE;
import com.css.sword.kernel.base.annotation.PersistObject;
import com.css.sword.kernel.base.dataElement.AbsPersistObject;
import com.css.sword.kernel.base.dataElement.BaseDataElement;
import com.css.sword.kernel.base.dataElement.DateDE;
import com.css.sword.kernel.base.exception.SwordBaseCheckedException;


/**
 * 手机应用版本维护表; InnoDB free: 11264 kB
 */
@PersistObject
public class TAppversionPO extends AbsPersistObject {
	//private static final long serialVersionUID = -5405350535845523383L;
	private static final long serialVersionUID = 1L;
	private static final BitSet HAS_DEFAULT_VALUE = new BitSet(6);
	
	static{
	}
	
	/**
	 * 物理表名
	 */
	public static final String TABLE_NAME = "t_appversion";

	/**
	 * 手机应用版本主键id
	 */
	private DE_APPVERSION_ID appversionId = DE_APPVERSION_ID.getTemplateInstance();

	/**
	 * 手机类型
	 */
	private DE_PHONETYPE phonetype = DE_PHONETYPE.getTemplateInstance();

	/**
	 * 手机应用版本号
	 */
	private DE_APPVERSION_NUMBER appversionNumber = DE_APPVERSION_NUMBER.getTemplateInstance();

	/**
	 * 手机应用更新地址
	 */
	private DE_APPVERSION_UPDATEURL appversionUpdateurl = DE_APPVERSION_UPDATEURL.getTemplateInstance();

	/**
	 * 手机应用版本维护操作时间
	 */
	private DE_APPVERSION_OPPTIME appversionOpptime = DE_APPVERSION_OPPTIME.getTemplateInstance();

	/**
	 * 手机应用版本更新内容
	 */
	private DE_APPVERSION_UPDATEINFO appversionUpdateinfo = DE_APPVERSION_UPDATEINFO.getTemplateInstance();


	public TAppversionPO(){
		this.insertState = new BitSet(6);
		this.updateState = new BitSet(6);
	}

	
	/**
	 * 获取 "手机应用版本主键id" 值
	 */	
	public DE_APPVERSION_ID getAppversionId(){
		return  appversionId;
	}
	
	/**
	 * 设置 "手机应用版本主键id" 值
	 */
	public void setAppversionId(DE_APPVERSION_ID appversionId) {
		if(appversionId == null){
			appversionId= DE_APPVERSION_ID.getTemplateInstance();
		}
		recordChangeFlag(0);
		this.appversionId = appversionId;
	}
	
	/**
	 * 获取 "手机类型" 值
	 */	
	public DE_PHONETYPE getPhonetype(){
		return  phonetype;
	}
	
	/**
	 * 设置 "手机类型" 值
	 */
	public void setPhonetype(DE_PHONETYPE phonetype) {
		if(phonetype == null){
			phonetype= DE_PHONETYPE.getTemplateInstance();
		}
		recordChangeFlag(1);
		this.phonetype = phonetype;
	}
	
	/**
	 * 获取 "手机应用版本号" 值
	 */	
	public DE_APPVERSION_NUMBER getAppversionNumber(){
		return  appversionNumber;
	}
	
	/**
	 * 设置 "手机应用版本号" 值
	 */
	public void setAppversionNumber(DE_APPVERSION_NUMBER appversionNumber) {
		if(appversionNumber == null){
			appversionNumber= DE_APPVERSION_NUMBER.getTemplateInstance();
		}
		recordChangeFlag(2);
		this.appversionNumber = appversionNumber;
	}
	
	/**
	 * 获取 "手机应用更新地址" 值
	 */	
	public DE_APPVERSION_UPDATEURL getAppversionUpdateurl(){
		return  appversionUpdateurl;
	}
	
	/**
	 * 设置 "手机应用更新地址" 值
	 */
	public void setAppversionUpdateurl(DE_APPVERSION_UPDATEURL appversionUpdateurl) {
		if(appversionUpdateurl == null){
			appversionUpdateurl= DE_APPVERSION_UPDATEURL.getTemplateInstance();
		}
		recordChangeFlag(3);
		this.appversionUpdateurl = appversionUpdateurl;
	}
	
	/**
	 * 获取 "手机应用版本维护操作时间" 值
	 */	
	public DE_APPVERSION_OPPTIME getAppversionOpptime(){
		return  appversionOpptime;
	}
	
	/**
	 * 设置 "手机应用版本维护操作时间" 值
	 */
	public void setAppversionOpptime(DE_APPVERSION_OPPTIME appversionOpptime) {
		if(appversionOpptime == null){
			appversionOpptime= DE_APPVERSION_OPPTIME.getTemplateInstance();
		}
		recordChangeFlag(4);
		this.appversionOpptime = appversionOpptime;
	}
	
	/**
	 * 获取 "手机应用版本更新内容" 值
	 */	
	public DE_APPVERSION_UPDATEINFO getAppversionUpdateinfo(){
		return  appversionUpdateinfo;
	}
	
	/**
	 * 设置 "手机应用版本更新内容" 值
	 */
	public void setAppversionUpdateinfo(DE_APPVERSION_UPDATEINFO appversionUpdateinfo) {
		if(appversionUpdateinfo == null){
			appversionUpdateinfo= DE_APPVERSION_UPDATEINFO.getTemplateInstance();
		}
		recordChangeFlag(5);
		this.appversionUpdateinfo = appversionUpdateinfo;
	}


	@Override
	public BaseDataElement<?>[] fields(){
		return new BaseDataElement<?>[] {appversionId,phonetype,appversionNumber,appversionUpdateurl,appversionOpptime,appversionUpdateinfo};
	}
	
	@Override
	public String[] fieldNames() {
		return new String[]{"appversionId","phonetype","appversionNumber","appversionUpdateurl","appversionOpptime","appversionUpdateinfo"};
	}
	
	@Override
	public BaseDataElement<?> getFieldValue(String fieldName)  {
		if ("appversionId".equals(fieldName)) {
			return appversionId;
		}
		if ("phonetype".equals(fieldName)) {
			return phonetype;
		}
		if ("appversionNumber".equals(fieldName)) {
			return appversionNumber;
		}
		if ("appversionUpdateurl".equals(fieldName)) {
			return appversionUpdateurl;
		}
		if ("appversionOpptime".equals(fieldName)) {
			return appversionOpptime;
		}
		if ("appversionUpdateinfo".equals(fieldName)) {
			return appversionUpdateinfo;
		}
 
		throw new IllegalArgumentException("PO对象中没有"+fieldName+"字段");
	}
	
	@Override
	public TAppversionPO setFieldValue(String fieldName, Object fieldValue) throws SwordBaseCheckedException {
		if (fieldValue != null && !(fieldValue instanceof BaseDataElement<?>)) {
			throw new SwordBaseCheckedException("字段值类型不是DataElelement子类型");
		}

		if ("appversionId".equals(fieldName)) {
			if (fieldValue == null) {
				setAppversionId(null);
			} else {
				setAppversionId((DE_APPVERSION_ID) fieldValue);
			}
			return this;
		}

		if ("phonetype".equals(fieldName)) {
			if (fieldValue == null) {
				setPhonetype(null);
			} else {
				setPhonetype((DE_PHONETYPE) fieldValue);
			}
			return this;
		}

		if ("appversionNumber".equals(fieldName)) {
			if (fieldValue == null) {
				setAppversionNumber(null);
			} else {
				setAppversionNumber((DE_APPVERSION_NUMBER) fieldValue);
			}
			return this;
		}

		if ("appversionUpdateurl".equals(fieldName)) {
			if (fieldValue == null) {
				setAppversionUpdateurl(null);
			} else {
				setAppversionUpdateurl((DE_APPVERSION_UPDATEURL) fieldValue);
			}
			return this;
		}

		if ("appversionOpptime".equals(fieldName)) {
			if (fieldValue == null) {
				setAppversionOpptime(null);
			} else {
				setAppversionOpptime((DE_APPVERSION_OPPTIME) fieldValue);
			}
			return this;
		}

		if ("appversionUpdateinfo".equals(fieldName)) {
			if (fieldValue == null) {
				setAppversionUpdateinfo(null);
			} else {
				setAppversionUpdateinfo((DE_APPVERSION_UPDATEINFO) fieldValue);
			}
			return this;
		}

		throw new SwordBaseCheckedException("PO对象中没有"+fieldName+"字段");
	}

	@Override
	protected TAppversionPO clone() {
		TAppversionPO t = new TAppversionPO();
		
		t.setAppversionId(this.appversionId);
		t.setPhonetype(this.phonetype);
		t.setAppversionNumber(this.appversionNumber);
		t.setAppversionUpdateurl(this.appversionUpdateurl);
		t.setAppversionOpptime(this.appversionOpptime);
		t.setAppversionUpdateinfo(this.appversionUpdateinfo);

		return t;
	}

	@Override
	public TAppversionPO loadMap(Map<String, Object> dataMap) throws SwordBaseCheckedException {
		Object value = null;

		if(dataMap.containsKey("appversionId")){
			value = dataMap.get("appversionId");
			
			if (value == null) {
				this.setAppversionId(null);
			} else {
				if (value instanceof DE_APPVERSION_ID) {
					this.setAppversionId((DE_APPVERSION_ID) value);
				}
			    else {
					this.setAppversionId(new DE_APPVERSION_ID(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("phonetype")){
			value = dataMap.get("phonetype");
			
			if (value == null) {
				this.setPhonetype(null);
			} else {
				if (value instanceof DE_PHONETYPE) {
					this.setPhonetype((DE_PHONETYPE) value);
				}
			    else {
					this.setPhonetype(new DE_PHONETYPE(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("appversionNumber")){
			value = dataMap.get("appversionNumber");
			
			if (value == null) {
				this.setAppversionNumber(null);
			} else {
				if (value instanceof DE_APPVERSION_NUMBER) {
					this.setAppversionNumber((DE_APPVERSION_NUMBER) value);
				}
			    else {
					this.setAppversionNumber(new DE_APPVERSION_NUMBER(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("appversionUpdateurl")){
			value = dataMap.get("appversionUpdateurl");
			
			if (value == null) {
				this.setAppversionUpdateurl(null);
			} else {
				if (value instanceof DE_APPVERSION_UPDATEURL) {
					this.setAppversionUpdateurl((DE_APPVERSION_UPDATEURL) value);
				}
			    else {
					this.setAppversionUpdateurl(new DE_APPVERSION_UPDATEURL(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("appversionOpptime")){
			value = dataMap.get("appversionOpptime");
			
			if (value == null) {
				this.setAppversionOpptime(null);
			} else {
				if (value instanceof DE_APPVERSION_OPPTIME) {
					this.setAppversionOpptime((DE_APPVERSION_OPPTIME) value);
				}
				else if(value instanceof java.util.Date){
					this.setAppversionOpptime(new DE_APPVERSION_OPPTIME((java.util.Date)value));
				}
			    else {
					this.setAppversionOpptime(new DE_APPVERSION_OPPTIME(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("appversionUpdateinfo")){
			value = dataMap.get("appversionUpdateinfo");
			
			if (value == null) {
				this.setAppversionUpdateinfo(null);
			} else {
				if (value instanceof DE_APPVERSION_UPDATEINFO) {
					this.setAppversionUpdateinfo((DE_APPVERSION_UPDATEINFO) value);
				}
			    else {
					this.setAppversionUpdateinfo(new DE_APPVERSION_UPDATEINFO(value.toString()));
				}
			}
		}

		return this;
	}
	
	@Override
	public Map<String,Object> toMap() {
		Map<String,Object> dataMap = new HashMap<String,Object>();

		dataMap.put("appversionId", appversionId);
		dataMap.put("phonetype", phonetype);
		dataMap.put("appversionNumber", appversionNumber);
		dataMap.put("appversionUpdateurl", appversionUpdateurl);
		dataMap.put("appversionOpptime", appversionOpptime);
		dataMap.put("appversionUpdateinfo", appversionUpdateinfo);
		
		return dataMap;
	}
	
	@Override
	public Map<String,Object> toMapWithDEValue() {
		Map<String,Object> dataMap = new HashMap<String,Object>();

		dataMap.put("appversionId", (appversionId==null?null:appversionId.value));
		dataMap.put("phonetype", (phonetype==null?null:phonetype.value));
		dataMap.put("appversionNumber", (appversionNumber==null?null:appversionNumber.value));
		dataMap.put("appversionUpdateurl", (appversionUpdateurl==null?null:appversionUpdateurl.value));
		dataMap.put("appversionOpptime", (appversionOpptime==null?null:appversionOpptime.value));
		dataMap.put("appversionUpdateinfo", (appversionUpdateinfo==null?null:appversionUpdateinfo.value));
		
		return dataMap;
	}
	
	@Override
	public TAppversionPO newInstance() {
		return new TAppversionPO();
	}
	
	@Override
	public String getTableName(){
		return TABLE_NAME;
	}
	
	@Override
	public BaseDataElement<?>[] getPrimaryKey() {
		return new BaseDataElement<?>[]{appversionId};
	}

	@Override
	public void checkNotNull(byte sqlType) throws SwordBaseCheckedException {
		StringBuilder errorMsg = new StringBuilder();
		// insert
		if (sqlType == 0) {
				//只校验不可为空但又没有默认值的字段
				if (appversionId.value == null && !HAS_DEFAULT_VALUE.get(0)) {
					errorMsg.append("字段appversionId不允许为空\n");
				}
				if (phonetype.value == null && !HAS_DEFAULT_VALUE.get(1)) {
					errorMsg.append("字段phonetype不允许为空\n");
				}
				if (appversionNumber.value == null && !HAS_DEFAULT_VALUE.get(2)) {
					errorMsg.append("字段appversionNumber不允许为空\n");
				}
				if (appversionUpdateurl.value == null && !HAS_DEFAULT_VALUE.get(3)) {
					errorMsg.append("字段appversionUpdateurl不允许为空\n");
				}

		}
		// update
		else if (sqlType == 1) {
		if (updateState.get(0) && appversionId.value == null) {
			errorMsg.append("字段appversionId不允许为空\n");
		}
		if (updateState.get(1) && phonetype.value == null) {
			errorMsg.append("字段phonetype不允许为空\n");
		}
		if (updateState.get(2) && appversionNumber.value == null) {
			errorMsg.append("字段appversionNumber不允许为空\n");
		}
		if (updateState.get(3) && appversionUpdateurl.value == null) {
			errorMsg.append("字段appversionUpdateurl不允许为空\n");
		}

		}
		
		if (errorMsg.length() > 0) {
			errorMsg.setLength(errorMsg.length() - 1);
			throw new SwordBaseCheckedException(errorMsg.toString());
		}
	}

	@Override
	public void updateLrrq(DateDE lrrq) {
	}

	@Override
	public void updateXgrq(DateDE xgrq) {
	}

	@Override
	public String toString() {
		StringBuilder str = new StringBuilder();
		str.append("appversionId:").append(appversionId.value!=null?appversionId:"").append(" ").append("phonetype:").append(phonetype.value!=null?phonetype:"").append(" ").append("appversionNumber:").append(appversionNumber.value!=null?appversionNumber:"").append(" ").append("appversionUpdateurl:").append(appversionUpdateurl.value!=null?appversionUpdateurl:"").append(" ").append("appversionOpptime:").append(appversionOpptime.value!=null?appversionOpptime:"").append(" ").append("appversionUpdateinfo:").append(appversionUpdateinfo.value!=null?appversionUpdateinfo:"").append(" ");
		return str.toString();
	}
	
}
